Map the exception method name to ERROR severity#156
Open
jeremyk wants to merge 1 commit into
Open
Conversation
structlog.stdlib.BoundLogger.exception() logs with the method name "exception", which isn't in SEVERITY_MAPPING, so it fell back to the DEFAULT severity. The default BoundLogger is unaffected (it uses "error").
multani
reviewed
Jul 1, 2026
Comment on lines
+68
to
+75
| def test_exception_method_maps_to_error_severity() -> None: | ||
| """`structlog.stdlib.BoundLogger.exception()` logs with the "exception" | ||
| method name, unlike the default ``BoundLogger`` (which uses "error"). It | ||
| must still map to ERROR severity. | ||
| """ | ||
| event_dict = LogSeverity()(None, "exception", {CLOUD_LOGGING_KEY: {}}) | ||
|
|
||
| assert event_dict[CLOUD_LOGGING_KEY]["severity"] == "ERROR" |
Owner
There was a problem hiding this comment.
Could you change the test to:
- Get a logger bound to a stdlib logger
- Call the stdlib-bound logger with an exception (cf. the test just below)
- Assert the output like the other test
You can add the "logger bound with a stdlib logger" as a new fixture into conftests.py ; I suspect it might be useful for other tests as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
structlog.stdlib.BoundLogger.exception()logs with the method name"exception", which isn't inSEVERITY_MAPPING— sologger.exception()falls back toDEFAULTseverity instead ofERROR. The defaultBoundLoggeris unaffected (its.exception()uses"error").Adds
"exception": "ERROR"to the mapping and a test.Example of

logger.exception()before:Fixes: #155